import { SendUsers } from './sendUser';
let _SendUsers = SendUsers;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import SendUserMock from './mdp/arc/send/sendUserMock';
 * SendUserMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/send/sendUser/listKey').reply(config => {
      let params = config.params;
      let mockSendUsers = _SendUsers.filter(sendUser => {
      	if(params.id||params.id==''){ if( sendUser.id.indexOf(params.id)>=0) return true;}
      	if(params.userid||params.userid==''){ if( sendUser.userid.indexOf(params.userid)>=0) return true;}
      	if(params.remark||params.remark==''){ if( sendUser.remark.indexOf(params.remark)>=0) return true;}
      	if(params.isGet||params.isGet==''){ if( sendUser.isGet.indexOf(params.isGet)>=0) return true;}
      	if(params.replyTime||params.replyTime==''){ if( sendUser.replyTime.indexOf(params.replyTime)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( sendUser.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.sendDate||params.sendDate==''){ if( sendUser.sendDate.indexOf(params.sendDate)>=0) return true;}
      	if(params.sendPlanId||params.sendPlanId==''){ if( sendUser.sendPlanId.indexOf(params.sendPlanId)>=0) return true;}
      	if(params.isSendSuccess||params.isSendSuccess==''){ if( sendUser.isSendSuccess.indexOf(params.isSendSuccess)>=0) return true;}
      	if(params.replyMsg||params.replyMsg==''){ if( sendUser.replyMsg.indexOf(params.replyMsg)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockSendUsers
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/send/sendUser/list').reply(config => {
      let params = config.params;
      let mockSendUsers = _SendUsers.filter(sendUser => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(sendUser.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(sendUser.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(sendUser.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isGet||params.isGet==''){if(sendUser.isGet.indexOf(params.isGet)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.replyTime||params.replyTime==''){if(sendUser.replyTime.indexOf(params.replyTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(sendUser.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendDate||params.sendDate==''){if(sendUser.sendDate.indexOf(params.sendDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendPlanId||params.sendPlanId==''){if(sendUser.sendPlanId.indexOf(params.sendPlanId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendSuccess||params.isSendSuccess==''){if(sendUser.isSendSuccess.indexOf(params.isSendSuccess)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.replyMsg||params.replyMsg==''){if(sendUser.replyMsg.indexOf(params.replyMsg)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockSendUsers
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockSendUsers.length;
      mockSendUsers = mockSendUsers.filter((sendUser, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockSendUsers,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/send/sendUser/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _SendUsers = _SendUsers.filter(sendUser => sendUser.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/send/sendUser/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _SendUsers = _SendUsers.filter(sendUser => !params.includes(sendUser.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/send/sendUser/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,userid,remark,isGet,replyTime,createDate,sendDate,sendPlanId,isSendSuccess,replyMsg } = params;
      _SendUsers.some(sendUser => {
        if (sendUser.id === id) {
			sendUser.id = id;
			sendUser.userid = userid;
			sendUser.remark = remark;
			sendUser.isGet = isGet;
			sendUser.replyTime = replyTime;
			sendUser.createDate = createDate;
			sendUser.sendDate = sendDate;
			sendUser.sendPlanId = sendPlanId;
			sendUser.isSendSuccess = isSendSuccess;
			sendUser.replyMsg = replyMsg
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/send/sendUser/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,userid,remark,isGet,replyTime,createDate,sendDate,sendPlanId,isSendSuccess,replyMsg } = params;
      _SendUsers.push({
		id:id,
		userid:userid,
		remark:remark,
		isGet:isGet,
		replyTime:replyTime,
		createDate:createDate,
		sendDate:sendDate,
		sendPlanId:sendPlanId,
		isSendSuccess:isSendSuccess,
		replyMsg:replyMsg
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};